import type { ElementConfig } from '../../types/constants'
import { ELEMENT_NAMESPACE_SEPARATOR, HOSTNAME, SUPPORTED_PLATFORMS } from '../../types/constants'

/* =============================== 元素配置 =============================== */
interface StylesConfig {
  [hostname: string]: {
    [style: string]: any
  }
}

const DEFAULT_CONFIG = {
  rightOffset: 850,
  topOffset: 110,
}

// 创建包含所有平台的默认配置
const CONFIG: StylesConfig = Object.fromEntries(
  Object.values(SUPPORTED_PLATFORMS).map(platform => [platform, DEFAULT_CONFIG]),
)

// 只覆盖需要特殊处理的平台
Object.assign(CONFIG, {
  [SUPPORTED_PLATFORMS.ZHI_HU]: {
    ...DEFAULT_CONFIG,
    rightOffset: 800,
    topOffset: 100,
  },
  [SUPPORTED_PLATFORMS.JIAN_SHU]: {
    ...DEFAULT_CONFIG,
    rightOffset: 800,
    topOffset: 100,
  },
})

export const elementConfig = {
  getConfig: (): {
    [style: string]: any
  } => {
    const [platform] = Object.keys(CONFIG)
      .filter(k => HOSTNAME.includes(k))
    return CONFIG[platform] || {}
  },
}

/**
 * 为配置对象添加前缀
 */
export function addPrefixToConfig(config: Record<string, ElementConfig>, namespace: string): Record<string, ElementConfig> {
  const separator = ELEMENT_NAMESPACE_SEPARATOR
  const prefixedConfig: Record<string, ElementConfig> = {}

  for (const [key, value] of Object.entries(config)) {
    const prefixedKey = `${namespace}${separator}${key}`

    prefixedConfig[prefixedKey] = {
      ...value,
      // nameEn: `${namespace}${ToolKit.string.capitalizeFirstLetter(value.nameEn || '')}`,
    }
  }

  return prefixedConfig
}
